%{
/* C++ string header, for string ops below */
#include <string>
#include <iostream>
#include <stdlib.h>
/* Implementation of yyFlexScanner */ 
#include "mc_scanner.hpp"

/* typedef to make the returns for the tokens shorter */
typedef MC::MC_Parser::token token;

/* define to keep from re-typing the same code over and over */
#define STOKEN( x ) ( new std::string( x ) )

/* define yyterminate as this instead of NULL */
#define yyterminate() return(token::END)

/* msvc2010 requires that we exclude this header file. */
#define YY_NO_UNISTD_H

%}

%option debug 
%option nodefault 
%option yyclass="MC_Scanner" 
%option noyywrap 
%option c++

letter               [A-Za-z]
digit                [0-9]
num                  {digit}+
identifier           {letter}({letter}|{digit}|_)*


%%
[ \n\t]              {/* ignore spaces, tabs, and newlines */}

{num}                {
                        std::cout<<"lexer:num:"<<yytext<<std::endl;
					    sscanf(yytext,"%d", &yylval->ival);
						return token::T_INT;
				     }


{num}\.{num}         {
                       std::cout<<"lexer:float:"<<yytext<<std::endl;
                       yylval->rval = atof(yytext);
                       return token::T_REAL;
                     }




{identifier}         {
                        std::cout<<"lexer:id:"<<yytext<<std::endl;
                        yylval->sval = yytext;
                        return token::T_STRING;
                     }

"<"                  {return token::T_LT;}
"<="                 {return token::T_LE;}
">"                  {return token::T_GT;}
">="                 {return token::T_GE;}
"="                  {return token::T_EQ;}
"!="                 {return token::T_NE;}
"<>"                 {return token::T_NE;}

[*/+\-=<>':;,.|&()]  {return yytext[0];}
"["                  {return yytext[0];}
"]"                  {return yytext[0];}
"$"                  {return yytext[0];}
.                    {
                       /* ignore '\0' */ 
                       if(yytext[0] > 0)
                          printf("illegal character [%c]\n", yytext[0]);
                     }
%%
